package thunderbirdgtd.entities;

import java.util.*;

public class Action extends BaseActionOrProject {
	
	private Project parentProject;
	private Date creationDate;
	private static int idLast;
	
	public Action(String name){
		this.name = name;
		this.creationDate = new Date();
		this.id = idLast++;
	}
	
	public Action(String name, Date creationDate, int id){
		this.name = name;
		this.creationDate = creationDate;
		this.assignedTags = new LinkedList<Tag>();
		this.id = id;
		
		if(id > idLast)
			idLast = id+1;
	}
	
	public void setParentProject(Project p) {
		parentProject = p;
	}

	
	


	public void setName(String name) {
		this.name = name;
	}

	public int getId() {
		return id;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public Project getParentProject() {
		return parentProject;
	}
	
	public static Action searchActionInLinkedList(String actionName, LinkedList<Action> ll) throws Exception {
		if (ll == null)
			throw new Exception("null list");
		ListIterator<Action> li = (ListIterator<Action>) ll.listIterator();
		Action action = null;
		while(li.hasNext()){
			action = li.next();
			if (action.name.equals(actionName))
				return action;
		}
		return null;
	}
	
	public String toString() {
		return "Name: " + getName() + " ID: " + getId() + " Date: " + getCreationDate() + "priority:" + getPriority();
	}


	

}
